package org.example.spring_book.controller;

import jakarta.servlet.http.HttpSession;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.example.spring_book.service.UserService;

@Slf4j
@RequestMapping("/user")
@RestController
public class UserController {
    @Autowired
    private UserService userService;
    @RequestMapping("/login")
    public Boolean login(String name, String password, HttpSession session) {
        log.info("接收到的参数:" + name);
        //从数据库中校验密码是否正确, 数据库中存在的才能登录
        //如果正确  存储session 返回 true
        //校验参数的格式
        Boolean result = userService.checkUserAndPassword(name,password,session);
        log.info("用户登录结果,name:{},结果: {}",name,result);
        return result;
    }

}
